package com.syl.practice.globalException2.result;

import com.syl.practice.globalexception.enums.ApiEnum;
import com.syl.practice.globalexception.exception.ApiException;
import lombok.Data;

import java.io.Serializable;

/**
 * 返回结果封装类
 */
@Data
public class RespResult implements Serializable {

    /**
     * 返回码
     */
    private int code;

    /**
     * 返回信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private Object data;

    public RespResult() {
        this.code = ApiEnum.SUCCESS.getCode();
        this.msg = ApiEnum.SUCCESS.getName();
    }

    public RespResult(Object obj) {
        this.code = ApiEnum.SUCCESS.getCode();
        this.msg = ApiEnum.SUCCESS.getName();
        this.data = obj;
    }

    public RespResult(ApiException e) {
        this.code = e.getCode();
        this.msg = e.getMsg();
    }
}
